<?php
require_once 'protected/extensions/BraintreePHPSDK/Braintree.php';

class Braintree extends PaymentAPI{

	const API_NAME = 'Braintree';

	private	$_paymentInfo;
	private $_result;
	
	public function apiInit(){
		$this->setApiName(self::API_NAME);
		Braintree_Configuration::environment('sandbox');
		Braintree_Configuration::merchantId('ppphc8h79gvg9ny8');
		Braintree_Configuration::publicKey('xhvjbvww8ts7dnkz');
		Braintree_Configuration::privateKey('8b8d807c0c2da5a915565fabcbdeda11');
		return $this;
	}
	
	public function apiRequest($request = null){
		$this->_result = Braintree_Transaction::sale(array(
			'amount' => round($this->totalPrice,2),
			'creditCard' => array(
				'number' => $this->creditCardInfo->cardNumber,
				'expirationDate' => date('m/y',$this->creditCardInfo->cardExpDate),
				'cvv' => $this->creditCardInfo->cardCode,
			),
		));
	}
	
	public function apiResponse($response = null){
		return $this->_result;
	}
	
	public function apiPaymentVaild(){
		if($this->_result->success){
			return true;
		}else{
			return false;
		}
	}
	
}